package com.example.exercise.app.feedbackreply.service.impl;

import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.example.exercise.app.feedbackreply.dto.request.AppReplyRequest;
import com.example.exercise.app.feedbackreply.dto.response.AppReplyResponse;
import com.example.exercise.app.feedbackreply.mapper.entity.AppReplyEntity;
import com.example.exercise.app.feedbackreply.service.AppReplyService;
import com.example.exercise.app.feedbackreply.mapper.AppReplyMapper;

@Service
public class AppReplyServiceImpl implements AppReplyService {

	@Resource
	private AppReplyMapper appReplyMapper;

	@Override
	public List<AppReplyResponse> findByWhere(AppReplyRequest appReplyRequest){
		List<AppReplyResponse> list = new ArrayList<>();
		appReplyRequest.setBegin((appReplyRequest.getCurrentPage() - 1) * appReplyRequest.getPageSize());
		List<AppReplyEntity> list0 = appReplyMapper.findByWhere(appReplyRequest);
		for (AppReplyEntity appReplyEntity : list0) {
			AppReplyResponse appReplyResponse = new AppReplyResponse();
			BeanUtils.copyProperties(appReplyEntity,appReplyResponse);
			list.add(appReplyResponse);
		}
		return list;
	}

	@Override
	public Integer getCountByWhere(AppReplyRequest appReplyRequest){
		return appReplyMapper.getCountByWhere(appReplyRequest);
	}

	@Override
	public AppReplyResponse findById(Integer id){
		AppReplyResponse appReplyResponse = new AppReplyResponse();
		AppReplyEntity appReplyEntity = appReplyMapper.findById(id);
		BeanUtils.copyProperties(appReplyEntity,appReplyResponse);
		return appReplyResponse;
	}

	@Override
	public int insertAppReply(AppReplyRequest appReplyRequest){
		AppReplyEntity appReplyEntity = new AppReplyEntity();
		BeanUtils.copyProperties(appReplyRequest,appReplyEntity);
        appReplyEntity.setCreattime(new Timestamp(System.currentTimeMillis()));
		return appReplyMapper.insertAppReply(appReplyEntity);
	}

	@Override
	public int updateAppReply(AppReplyRequest appReplyRequest){
		AppReplyEntity appReplyEntity = new AppReplyEntity();
		BeanUtils.copyProperties(appReplyRequest,appReplyEntity);
		return appReplyMapper.updateAppReply(appReplyEntity);
	}

	@Override
	public int deleteById(Integer id){
		return appReplyMapper.deleteById(id);
	}

}